var img_logo = document.querySelector('.img_logo');
var time = document.querySelector('.time');
var userMesg= document.querySelector('.userMesg span');
// 页面加载
function PageInit() {
    // 初始化用户登录信息
    var loginName=getLoginName();
    if(loginName != null) {
        img_logo.innerHTML =loginName;
        userMesg.innerHTML = `你好! ${loginName},欢迎回来`;
    }else {
      location.href = 'login.html';
    }

    // 初始化当前系统时间
    initDateTime();
  
    // 初始化数据统计
}
PageInit();

function getLoginName() {
    return localStorage.getItem("longinName");
}

function initDateTime() {
    var dt = new Date();
    time.innerHTML = dt.toLocaleString();
    setTimeout(function(){
      initDateTime();
    },1000);
}

// 点击退出登录
var userOut = document.querySelector('.userOut');
userOut.onclick = function() {
    // 清空登录用户信息
    localStorage.removeItem("longinName");
    // 跳转到登录页面
    location.href = 'login.html';
};


// 点击左侧导航列表
function listClick() {
        var span = document.querySelectorAll(".list span");
        span.forEach(function(item){
          item.addEventListener('click', function(){
              this.classList.toggle("active");
              var content = this.nextElementSibling;
              if(this.className == "active") {
                content.style.padding = "10px 0";
                content.style.height = "auto";
              }else {
                content.style.padding = "0";
                content.style.height = "0";
              }
          });
        });
};
listClick();